package com.lijie.ljblog.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.api.R;
import com.lijie.ljblog.model.Link;
import com.lijie.ljblog.service.LinkService;
import com.lijie.ljblog.util.QueryWrapperUtil;
import com.lijie.ljblog.util.Result;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Title: ljblog_springboot
 * @Description: ()
 * @Author:lijie
 * @Version:1.1.0
 * @since 2021/11/26
 */
@RestController
@RequestMapping("/ljblog/Link")
public class LinkController {
    @Resource
    LinkService linkService;

    @Resource
    QueryWrapperUtil queryWrapperUtil;

    //友链
    @RequestMapping("saveOrUpdate")
    public Result<Boolean> saveOrUpdate(@RequestBody Link link){
        Result<Boolean> result=new Result<>();
        boolean b = linkService.saveOrUpdate(link);
        if(b){
            result.setSuccess();
        }else{
            result.setErrored();
        }
        return result;
    }

    //拿出友链
    @RequestMapping("getLinks")
    public Result<List<Link>> getLinks(@RequestBody Link link){
        Result<List<Link>> result=new Result<>();
        QueryWrapper<Link> linkQueryWrapper = queryWrapperUtil.getLinkQueryWrapper(link);
        List<Link> list = linkService.list(linkQueryWrapper);
        result.setSuccess();
        result.setData(list);
        return result;
    }

}
